package cn.coisini.controller.v1;

import cn.coisini.api.admin.RoleControllerApi;
import cn.coisini.model.common.annotation.RedisAccessLimit;
import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.common.log.annotation.Log;
import cn.coisini.model.common.log.enums.BusinessType;
import cn.coisini.model.pojo.Role;
import cn.coisini.model.vo.RoleQueryVo;
import cn.coisini.service.RoleService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 角色管理
 */
@RestController
@RequiredArgsConstructor
public class RoleController implements RoleControllerApi {

    private final RoleService roleService;

    // 根据id查询角色
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<Role> findRoleById(String id) {
        return roleService.findRoleById(id);
    }

    // 分页查询角色
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<Page<Role>> pagingQuery(RoleQueryVo roleQueryVo) {
        return roleService.pagingQuery(roleQueryVo);
    }

    // 添加角色
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "角色管理",businessType = BusinessType.INSERT)
    public Result<ResultEnum> saveRole(Role role) {
        return roleService.saveRole(role);
    }

    // 修改角色
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "角色管理",businessType = BusinessType.UPDATE)
    public Result<ResultEnum> updateRole(Role role) {
        return roleService.updateRole(role);
    }

    // 删除角色
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "角色管理",businessType = BusinessType.DELETE)
    public Result<Role> removeRole(String id) {
        return roleService.removeRole(id);
    }

    // 批量删除角色
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "角色管理",businessType = BusinessType.BATCH_REMOVE)
    public Result<ResultEnum> batchRemoveRole(List<String> ids) {
        return roleService.batchRemove(ids);
    }
}
